package com.lz.football.module.activity.festival
{
	import com.common.utils.Reflection;
	import com.global.GlobalDef;
	import com.liangzhong.constants.ResourceConst;
	import com.liangzhong.events.ActivityEvent;
	import com.liangzhong.events.ModuleEvent;
	import com.liangzhong.manager.ResourceManager;
	import com.liangzhong.message.http.JsClient;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.activity.vip.VipVo;
	import com.liangzhong.model.goods.vo.GoodsVo;
	import com.lz.football.module.activity.IActivity;
	
	import common.BaseView.BaseView;
	import common.BaseView.DisplayMouseEventManager;
	import common.BaseView.GoodItem;
	
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.MouseEvent;
	import flash.filters.ColorMatrixFilter;
	import flash.text.TextField;

	/**
	 *节日活动 
	 * @author Administrator
	 * 
	 */	
	public class FestivalView extends BaseView implements IActivity
	{
		
		/**
		 *vip等级 
		 */
		private var vipLv:MovieClip;
		
		/**
		 *容器 
		 */
		private var itemContain:MovieClip;
		/**
		 *查看按钮 
		 */
		private var lookBtn:SimpleButton;
		
		/**
		 * 领取按钮
		 */
		private var getBtn:SimpleButton;
		
		/**
		 *充值按钮 
		 */
		private var topupBtn:SimpleButton;
		/**
		 *查看奖励 
		 */
		private var _lookView:FestivalDailyView;
		
		/**
		 *活动时间 
		 */
		private var timeTxt:TextField;
		public function FestivalView()
		{
			super();
		}
		override public function initUI(view:Object=null):void
		{
			symbolSkin = Reflection.createInstance("com.lz.modul.festival.festivalView");
			this.addChild(symbolSkin);
			_windowBg = symbolSkin.festivalBg;
			_viewHeight = _windowBg.height;
			_viewWidth = _windowBg.width;
			isCloseBtn = true;
			isDrag = true;
			moveClose(_viewWidth - 30,25);
			vipLv = symbolSkin.vipLv;
			lookBtn = symbolSkin.lookBtn;
			getBtn = symbolSkin.getBtn;
			topupBtn = symbolSkin.topupBtn;
			itemContain = symbolSkin.itemContain;
			timeTxt = symbolSkin.timeTxt;
			timeTxt.text = "";

			
			vipLv.gotoAndStop(13);
			onResizeHandler();
			addEvtListener();
			showInfo();
			getBtnfilters = true;
			
			var xml:XML = ResourceManager.instance.getResource(ResourceConst.ACTIVITYTIME_XML);
			timeTxt.text = "" +xml.Festival + "截止";
		}
		
		private function showInfo():void
		{
			var Lv:int = AppData.getInstance().clubDatamanager.clubInfo.VIP;
			var vipVo:VipVo = AppData.getInstance().activityDatemanager.getActivityVipVo(Lv);
			if(Lv <= 0)
				vipLv.gotoAndStop(13);
			else
				vipLv.gotoAndStop(Lv);
			
			var arr:Array = vipVo.daily;
			var len:int = arr.length;
			var item:GoodItem;
//			itemContain.x = 
			for(var i:int = 0;i < len;i++)
			{
				item = new GoodItem();
				
				if(arr[i].goods != null)
				{
					item.initUI();
					item.data = arr[i].goods;
					item.showNameAndNum((item.data as GoodsVo).name +"*" +arr[i].num );
				}else
				{
					var mc:MovieClip= Reflection.createInstance("com.lz.commonUI.point");
					item.addChild(mc);
					mc.x = 0;
					item.showNameAndNum("点券* " +arr[i].num);
					DisplayMouseEventManager.instance.addTipsDisplay(item,"点券* " +arr[i].num);
				}
				
				item.x = 100 * itemContain.numChildren;
				itemContain.addChild(item);
			}
			itemContain.x = ((667 - 90 * len)>> 1) ;
		}
		public function baseinformation($obj:Object):void
		{
			//VIP节日大礼包奖励			0.未领取，1.已领取

			if($obj.holiday == 0)
			{
				getBtnfilters = true;
			}else
			{
				getBtnfilters = false;
			}
		}
		
		public function award($obj:Object):void
		{
			getBtn.addEventListener(MouseEvent.CLICK,onGetHandelr);
			if($obj.status)
			{
				getBtnfilters = false;
			}
		}
		private function set getBtnfilters(value:Boolean):void
		{
			if(value)
			{
				getBtn.filters = null;
				getBtn.mouseEnabled = true;
			}else
			{
				getBtn.filters = [new ColorMatrixFilter([0.3086, 0.6094, 0.082, 0, 0,
					0.3086, 0.6094, 0.082, 0, 0,
					0.3086, 0.6094, 0.082, 0, 0,
					0,0,0,1,0,])];
				getBtn.mouseEnabled = false;
			}
			
		}
		override public function addEvtListener():void
		{
			topupBtn.addEventListener(MouseEvent.CLICK,onTopupHandler);
			lookBtn.addEventListener(MouseEvent.CLICK,onLookHandler);
			getBtn.addEventListener(MouseEvent.CLICK,onGetHandelr);
		}
		
		/**
		 *领取按钮 
		 * @param event
		 * 
		 */
		protected function onGetHandelr(event:MouseEvent):void
		{
			// TODO Auto-generated method stub
			getBtn.removeEventListener(MouseEvent.CLICK,onGetHandelr);
			this.dispatchEvent(new ActivityEvent(ActivityEvent.ACTIVITY_FESTIVAL_VIP));
		}
		/**
		 *查看 
		 * @param event
		 * 
		 */		
		protected function onLookHandler(event:MouseEvent):void
		{
			// TODO Auto-generated method stub
			if(_lookView == null)
			{
				_lookView = new FestivalDailyView();
				_lookView.initUI();
			}
			GlobalDef.GameWindowContainer.addChild(_lookView);
		}
		
		protected function onTopupHandler(event:MouseEvent):void
		{
			// TODO Auto-generated method stub
			JsClient.recharge();
		}
		override public function removeEvtListener():void
		{
			topupBtn.addEventListener(MouseEvent.CLICK,onTopupHandler);
			lookBtn.addEventListener(MouseEvent.CLICK,onLookHandler);
			getBtn.addEventListener(MouseEvent.CLICK,onGetHandelr);
			super.removeEvtListener();
		}
		override public function destroyView():void
		{
			removeEvtListener();
			
			var item :GoodItem;
			while(itemContain.numChildren)
			{
				item = itemContain.removeChildAt(0) as GoodItem;
				item.destroyView();
				DisplayMouseEventManager.instance.removeTipsDisplay(item);
				item = null;
			}
			if(_lookView != null)
				_lookView.destroyView();
			_lookView = null;
			super.destroyView();
			
		}
		override public function onCloseHandler(event:MouseEvent):void
		{
			this.dispatchEvent(new ActivityEvent(ModuleEvent.REMOVE_MODULE));
		}
	}
}